package com.diy.sigmund.diycommon.test.spring.config;

import com.diy.sigmund.diycommon.test.config.entity.ImportPerson;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author ylm-sigmund
 * @see <a href="https://mp.weixin.qq.com/s?__biz=MzI1NDQ3MjQxNA==&mid=2247497785&idx=1&sn=4d795dfe3301166b3d84259b04b3f5bd">Spring中竟然有12种定义bean的方法</a>
 * @since 2021/10/23 19:47
 */
@Component
public class MyRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        RootBeanDefinition importPersonDefinition = new RootBeanDefinition(ImportPerson.class);
        importPersonDefinition.setScope(ConfigurableBeanFactory.SCOPE_SINGLETON);
        registry.registerBeanDefinition("importPerson", importPersonDefinition);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    }
}